package com.nulldev.util.web.HttpClient;

import com.nulldev.util.web.HttpServer3.legacyPages.v1.RequestType;

public enum HttpMethod {
	GET("GET"),
	POST("POST"),
	OPTIONS("OPTIONS"),
	PUT("PUT"),
	DELETE("DELETE"),
	HEAD("HEAD"),
	TRACE("TRACE"),
	PATCH("PATCH"),
	CONNECT("CONNECT")

	;

	private final String value;

	private HttpMethod(final String value) {
		this.value = value;
	}

	public String value() {
		return this.value;
	}

	public static HttpMethod as(final String e) {
		if (e == null || e.isEmpty())
			throw new NullPointerException();
		for (final HttpMethod f : values()) {
			if (f.name().equalsIgnoreCase(e))
				return f;
		}
		throw new UnsupportedOperationException("Unknown method: " + e);
	}

	public static HttpMethod convert(final RequestType type) {
		switch (type) {
			case GET:
				return GET;
			case CONNECT:
				return CONNECT;
			case DELETE:
				return DELETE;
			case HEAD:
				return HEAD;
			case OPTIONS:
				return OPTIONS;
			case PATCH:
				return PATCH;
			case POST:
				return POST;
			case PUT:
				return PUT;
			case TRACE:
				return TRACE;
			default:
				throw new UnsupportedOperationException("Unknown request type: " + type);
		}
	}
}
